# LOAD NECESSARY PACKAGES ------------------------------------------------------

library(pacman)

# tidyverse
p_load(dplyr, tidyr, stringr, forcats, purrr, ggplot2, ggalluvial, patchwork, 
       broom, ggridges)

#devtools::install_github("bcallaway11/did")

# analysis
p_load(naniar, fixest, did, modelsummary, broom)

# misc
p_load(here)

#sem
std <- function(x) sd(x, na.rm = T)/sqrt(length(x))

# LOAD DATA --------------------------------------------------------------------

eth_ntl <- read.csv(here("Data","RE _Revised_NTL_analysis", "ethiopia_ea_with_ntl.csv"))
nig_ntl <- read.csv(here("Data","RE _Revised_NTL_analysis", "nigeria_ea_with_ntl.csv"))

# Define treatment groups
a <- eth_ntl %>% 
  filter(year == 2013, ntl == 0) %>% 
  pull(ea)

b <- eth_ntl %>% 
  filter(year == 2015, ntl == 1) %>% 
  pull(ea)

eth_treated2015 <- intersect(a,b)

print(paste0("Ethiopia EAs only treated in 2015 - ", paste0("EA: ", eth_treated2015,",")))

# Define treatment groups
a <- nig_ntl %>% 
  filter(year == 2012, ntl == 0) %>% 
  pull(ea)

b <- nig_ntl %>% 
  filter(year == 2015, ntl == 1) %>% 
  pull(ea)

nig_treated2015 <- intersect(a,b)

print(paste0("Nigeria EAs only treated in 2015 - ", paste0("EA: ", nig_treated2015,",")))

